/*�û���Ϣ�߼���
 * 
 */
package software;

import java.sql.*;

import  software.Conn;

public class Use_done{
	public Boolean Che_NameR(String s){
		Boolean CHECK=true;
		try{
			String sql="{ call reg_checkn(?,?) }";
			Conn Dataconn=new Conn();
			Dataconn.Create();
			CallableStatement cs=Dataconn.CSt_SQL(sql);
			cs.setString(1, s);
			cs.registerOutParameter(2,java.sql.Types.INTEGER);
			if(cs.getInt(2)==1) CHECK=false;
			}catch(Exception e){
				e.printStackTrace();
			}
		return CHECK;
	}
	public boolean Che_EmailR(String s){
		boolean CHECK=true;
		try{
			String sql="{ call reg_checke(?,?) }";
			Conn Dataconn=new Conn();
			Dataconn.Create();
			CallableStatement cs=Dataconn.CSt_SQL(sql);
			cs.setString(1, s);
			cs.registerOutParameter(2,java.sql.Types.INTEGER);
			if(cs.getInt(2)==0) CHECK=false;
			}catch(Exception e){
				e.printStackTrace();
			}
		return CHECK;
	}
	public int RegisterR(String Name,String Pwd,String NickName,String Email,String Birthday,int Sex,String Photo){
		int I=0;
		String sql="{ call user_insert(?,?,?,?,?,?,?,?) }";
		try{
			Conn Dataconn=new Conn();
			Dataconn.Create();
			CallableStatement cs=Dataconn.CSt_SQL(sql);
			cs.registerOutParameter(1,java.sql.Types.INTEGER);
			cs.setString(2, Name); 
			cs.setString(3, Pwd); 
			cs.setString(4, NickName);
			cs.setString(5, Email);
			cs.setString(6,Birthday);
			cs.setInt(7,Sex);
			cs.setString(8,Photo);
			cs.execute(); 
			I=cs.getInt(1);
			Dataconn.CloseCC();
			}catch(Exception e){
				e.printStackTrace();
			}
		return I;
	}
	
	public int Che_Login(String Name,String Pwd){
		int I=0;
		String sql="{ call user_login(?,?,?) }";
		try{
			Conn Dataconn=new Conn();
			Dataconn.Create();
			CallableStatement cs=Dataconn.CSt_SQL(sql);
			cs.setString(1, Name); 
			cs.setString(2, Pwd); 
			cs.registerOutParameter(3,java.sql.Types.INTEGER);
			cs.execute(); 
			I=cs.getInt(3);
			Dataconn.CloseCC();
			}catch(Exception e){
				e.printStackTrace();
			}
		return I;
	}
	public void Use_delete(int id){
		
	}
	
	public int getId(String Name1){
		int Id=0;
		String sql="{ call get_id(?,?) }";
		try{
			Conn Dataconn=new Conn();
			Dataconn.Create();
			CallableStatement cs=Dataconn.CSt_SQL(sql);
			cs.setString(1, Name1); 
			cs.registerOutParameter(2,java.sql.Types.INTEGER);
			cs.execute(); 
			Id=cs.getInt(2);
			Dataconn.CloseC();
			}catch(Exception e){
				e.printStackTrace();
			}
		return Id;
	}
	
	public String getName(int id){
		String Nickname=null;
		String sql="{ call getname(?,?) }";
		try{
		Conn Dataconn=new Conn();
		Dataconn.Create();
		CallableStatement cs=Dataconn.CSt_SQL(sql);
		cs.setInt(1, id); 
		cs.registerOutParameter(2,java.sql.Types.CHAR);
		cs.execute(); 
		Nickname=cs.getString(2);
		Dataconn.CloseC();
		}catch(Exception e){
			e.printStackTrace();
		}
	return Nickname;
	}
}